import 'package:flutter/material.dart';

class BaseTitleBar extends StatelessWidget {
  String title;
  var leftIcon ;
  var rightIcon ;
  final VoidCallback rightClick;
  final VoidCallback leftClick;
  BaseTitleBar(this.title, {this.leftIcon, this.rightIcon, this.rightClick,this.leftClick});

  @override
  Widget build(BuildContext context) {
    return new AppBar(
      flexibleSpace: Container(
        color: Color(0xFF4188F2),
        /// 实现渐变色的效果
//        decoration: BoxDecoration(
//          gradient: LinearGradient(
//            colors: [
//              Color.fromRGBO(26, 155, 214, 1),
//              Color.fromRGBO(54, 209, 193, 1)
//            ],
//          ),
//        ),
      ),
      title: new Text(this.title,style: TextStyle(fontSize: 16),),
      leading:
      new LeftView(leftIcon, leftClick,),
//      new IconButton(
//        /// 左边图标，视情况而定，自己穿参数
//        icon: this.leftIcon,
//        color: Colors.white,
//        onPressed: () {
//          Navigator.pop(context);
//        },
//      ),
      brightness: Brightness.dark,
      elevation: 2.0,
      centerTitle: true,

      actions: <Widget>[
        /// 右边的 布局，自己可以添加，是一个widget的一个集合，自已需求添加即可，我这里写了一个Text，和text的点击事件，
        rightIcon.toString().length>2?new RightView(rightIcon,rightClick,):Container(),
      ],
    );
  }
}

/// 右边的 布局，以及点击事件
class RightView extends StatelessWidget {
  var title;
  VoidCallback rightClick;

  RightView(this.title, this.rightClick);

  @override
  Widget build(BuildContext context) {
    var containView;
    if (title != Null) {
      containView = new Container(
        alignment: Alignment.center,
        padding: EdgeInsets.all(10.0),
        child: GestureDetector(
          child: Container(
            width: 20,
            height: 20,
            child:
            Image.asset(title),
          ),
          onTap: this.rightClick,
        ),
      );
    } else {
      containView = Text("");
    }
    return containView;
  }

}

/// 右边的 布局，以及点击事件
class LeftView extends StatelessWidget {
  var title;
  VoidCallback rightClick;

  LeftView(this.title, this.rightClick);

  @override
  Widget build(BuildContext context) {
    var containView;
    if (title != Null) {
      containView = new Container(
        alignment: Alignment.center,
        padding: EdgeInsets.all(10.0),
        child: GestureDetector(
          child: Container(
            width: 20,
            height: 20,
            child:
            Image.asset(title),
          ),
          onTap: this.rightClick,
        ),
      );
    } else {
      containView = Text("");
    }
    return containView;
  }

}